package com.scrapy.regex;

import org.dom4j.Element;

import java.util.List;
import java.util.Properties;

/**
 * 解析XML标签中名为Joker标签下的内容
 * Created by wanter on 2016/11/7.
 */
public class RegexJoker {
    /**
     * 只能在这个地方进行追加
     */
    private Properties properties;

    public static final String JOKER = "joker";

    /**
     * 最最为重要的构造方法
     * @param properties
     */
    public RegexJoker(Element element, Properties properties){
        this.properties = properties;
        pase(element, properties );
    }

    private void pase(Element element, Properties properties){
        List<Element> lists = element.elements();
        for(Element e:lists){
            //System.out.println(e.getName()+this.getClass().getName());
            if(JOKER.equalsIgnoreCase(e.getName())){
                paseJoker(e,properties);

            }else{
                System.err.println("请在"+this.getClass().getName()+"添加相应的实现");
            }
        }
    }

    /**
     * 解析Joker标签
     * @param element
     * @param properties
     */
    private void paseJoker(Element element, Properties properties){
        List<Element> childEle = element.elements();
        for(Element ele : childEle)


            if("joke".equalsIgnoreCase(ele.getName())){
                System.out.println("进入解析joke中");
                paseJoke(ele,properties);
            }else if("author".equalsIgnoreCase(ele.getName())){
                System.out.println("进入解析author中");
                paseAuthor(ele,properties);
            }else {
                System.out.println("没有找到对应的");
            }
    }

    /**
     * 解析joke
     * @param element
     * @param properties
     */
    private void paseJoke(Element element, Properties properties){

        List<Element> elements = element.elements();
        for (Element e : elements){
            System.out.println(" 名字: " + e.getName()+"   值: "+e.getText());
        }
    }

    /**
     * 解析author
     * @param element
     * @param properties
     */
    private void paseAuthor(Element element, Properties properties){

    }

}
